package com.qin.mall.controller.ordercontroller;

import com.qin.mall.openfeign.order.OmsOrderFeigin;
import com.qin.mall.common.api.CommonResult;
import com.qin.mall.common.api.MyBatisPlusPage;
import com.qin.mall.domain.OmsOrder;
import com.qin.mall.dto.OmsOrderDeliveryParam;
import com.qin.mall.dto.OmsOrderDetail;
import com.qin.mall.dto.OmsOrderQueryParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Leisure
 * create 2022 2022/11/22 9:04
 **/
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OmsOrderFeigin orderFeigin;

    /**
     * 关键字查找并分页显示
     */
    @GetMapping("/list")
    @ResponseBody
    public CommonResult<MyBatisPlusPage<OmsOrder>> list(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                        @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
                                                        OmsOrderQueryParam queryParam) {
        CommonResult<MyBatisPlusPage<OmsOrder>> list = orderFeigin.listQuery(pageNum, pageSize, queryParam);
        return list;
    }

    /**
     * 获取指定订单详情
     */
    @GetMapping("/{id}")
    @ResponseBody
    public CommonResult<OmsOrderDetail> detail(@PathVariable Long id){
        CommonResult<OmsOrderDetail> detail = orderFeigin.detail(id);
        return detail;
    }

    /**
     * 修改订单备注 /这里原来是用post请求，但是我觉得用get更合理
     */
    @PostMapping("/update/note")
    public CommonResult updateNote(@RequestParam("id") Long id,
                                   @RequestParam("note") String note,
                                   @RequestParam("status") Integer status){
        CommonResult result = orderFeigin.updateNote(id, note, status);
        return result;
    }

    @PostMapping("/delete")
    public CommonResult delete(@RequestParam("ids") List<Long> ids){
        CommonResult delete = orderFeigin.delete(ids);
        return delete;
    }

    /**
     * 批量发货
     */
    @PostMapping("/update/delivery")
    public CommonResult delivery(@RequestBody List<OmsOrderDeliveryParam> deliveryParamList){
        CommonResult delivery = orderFeigin.delivery(deliveryParamList);
        return delivery;
    }

    /**
     *  批量关闭订单
     */
    @PostMapping("/update/close")
    public CommonResult close(@RequestParam("note") String note,
                              @RequestParam("ids") List<Long> ids){
        CommonResult close = orderFeigin.close(note, ids);
        return close;
    }
    
}